﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Business.IManager;
using Business.Manager;
using Utility;
using System.Data;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace OnlinePayment.OP
{
    public partial class OrderInfoView : System.Web.UI.Page
    {
        IOrderManager orderManager = new OrderManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                /*if (Session["User"] == null)
                {
                    Response.Redirect("/Account/LogIn.aspx");
                }
                else
                {*/
                String[] kind = { "请选择", "水电费", "一卡通", "校园网", "学费/双专业费/重修费" };
                kindList.DataSource = kind;
                kindList.DataBind();
                //lblStu.Text = Session["User"].ToString();
                //BindData();



            }
        }

        /*private void BindData()
        {
            Student student = (Student)Session["User"];
            string stuId = student.StudentId;
            utilityOrderList.DataSource = orderManager.getUtilityOrderInfor(stuId);//替换
            utilityOrderList.DataBind();
            utilityOrderList.Visible = true;
            netWortPortOrderList.DataSource = orderManager.getNetworkPortOrderInfor(stuId);
            netWortPortOrderList.DataBind();
            netWortPortOrderList.Visible = true;
            stuCardOrderList.DataSource = orderManager.getStuCardOrderInfor(stuId);
            stuCardOrderList.DataBind();
            stuCardOrderList.Visible = true;
            paymentProjectOrderList.DataSource = orderManager.getPaymentProjectInfor(stuId);
            paymentProjectOrderList.DataBind();
            paymentProjectOrderList.Visible = true;

        }*/

        protected void kindList_SelectedIndexChanged(object sender, EventArgs e)
        {
            String str = kindList.SelectedItem.Text;
            bindData(str);
           
        }


        private void bindData(string str)
        {
            Student student = (Student)Session["User"];
            string stuId = student.StudentId;
            //detailDiv.Visible = true;
            if (str.Equals("请选择"))
            {
                utilityOrderList.Visible = false;
                netWortPortOrderList.Visible = false;
                stuCardOrderList.Visible = false;
                paymentProjectOrderList.Visible = false;
            }
            /* else if (str.Equals("全部"))
             {
                 BindData();
                 utilityOrderList.Visible = true;
                 netWortPortOrderList.Visible = true;
                 stuCardOrderList.Visible = true;
                 paymentProjectOrderList.Visible = true;
             }*/
            else if (str.Equals("水电费"))
            {
                utilityOrderList.DataSource = orderManager.getUtilityOrderInfor(stuId);//替换
                utilityOrderList.DataBind();
                utilityOrderList.Visible = true;
                netWortPortOrderList.Visible = false;
                stuCardOrderList.Visible = false;
                paymentProjectOrderList.Visible = false;

            }
            else if (str.Equals("一卡通"))
            {
                stuCardOrderList.DataSource = orderManager.getStuCardOrderInfor(stuId);
                stuCardOrderList.DataBind();
                utilityOrderList.Visible = false;
                netWortPortOrderList.Visible = false;
                stuCardOrderList.Visible = true;
                paymentProjectOrderList.Visible = false;
            }
            else if (str.Equals("校园网"))
            {
                netWortPortOrderList.DataSource = orderManager.getNetworkPortOrderInfor(stuId);
                netWortPortOrderList.DataBind();
                utilityOrderList.Visible = false;
                netWortPortOrderList.Visible = true;
                stuCardOrderList.Visible = false;
                paymentProjectOrderList.Visible = false;
            }
            else
            {
                paymentProjectOrderList.DataSource = orderManager.getPaymentProjectInfor(stuId);
                paymentProjectOrderList.DataBind();
                utilityOrderList.Visible = false;
                netWortPortOrderList.Visible = false;
                stuCardOrderList.Visible = false;
                paymentProjectOrderList.Visible = true;
            }
        }



        protected void paymentProjectOrderList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Detail": //查看订单详细信息
                    string orderId = e.CommandArgument.ToString();
                    projectDetailList.DataSource = orderManager.getTuitionOrderDetailByOrderId(orderId);//
                    projectDetailList.DataBind();
                    detailDiv.Visible = true;
                    

                    break;
            }
        }









        protected void GV_PPO_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            // 得到该控件
            GridView theGrid = sender as GridView;
            int newPageIndex = 0;
            if (e.NewPageIndex == -3)
            {
                //点击了Go按钮
                TextBox txtNewPageIndex = null;

                //GridView较DataGrid提供了更多的API，获取分页块可以使用BottomPagerRow 或者TopPagerRow，当然还增加了HeaderRow和FooterRow
                GridViewRow pagerRow = theGrid.BottomPagerRow;

                if (pagerRow != null)
                {
                    //得到text控件
                    txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
                }
                if (txtNewPageIndex != null)
                {
                    //得到索引
                    newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
                }
            }
            else
            {
                //点击了其他的按钮
                newPageIndex = e.NewPageIndex;
            }

            //防止新索引溢出
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

            //得到新的值
            theGrid.PageIndex = newPageIndex;

            //重新绑定

            String str = kindList.SelectedItem.Text;
            bindData(str);

        }









    }
}